/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.vo.IsfdTreeNodeVo;
import com.comac.ins.isfd.domain.vo.MaterialCountObjectVo;
import com.comac.ins.isfd.service.IMaterialInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 材料库查询后台服务
 *
 * @author zb
 * @date 2024-06-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/material")
public class MaterialInfoController extends BaseController {

    private final IMaterialInfoService materialInfoService;

    /**
     * 查询材料库数据的树形接口
     */
    @SaCheckPermission("isfd:material:query")
    @GetMapping("/list/tree")
    @Operation(summary = "查询材料库数据的树形接口", security = @SecurityRequirement(name = "isfd:material:list"))
    public R<IsfdTreeNodeVo> listTree(@Parameter(description = "businessScenarioNo能为空，多个用逗号隔开", example = "1")
                                    @RequestParam(required = false, defaultValue = "1") String[] businessScenarioNo,
                                      @Parameter(description = "type能为空，多个用逗号隔开", example = "mat_material,comp_material")
                                    @RequestParam(required = false) String[] type,
                                      @Parameter(description = "detail能为空,true返回详细数据")
                                    @RequestParam(required = false) Boolean detail) {
        return R.ok(materialInfoService.queryTree(businessScenarioNo, type, false));
    }

    /**
     * 查询series下金属材料详细数据接口
     */
    @SaCheckPermission("isfd:material:query")
    @GetMapping("/list/detail/{businessScenarioNo}/{type}")
    @Operation(summary = "查询series下金属材料详细数据接口", security = @SecurityRequirement(name = "system:materialInfo:query"))
    public R<List<Map<String, Object>>> treeNodeDetail(@NotNull(message = "businessScenarioNo不能为空") @PathVariable String businessScenarioNo,
                                                       @NotNull(message = "type不能为空") @PathVariable String type,
                                                       @Parameter(description = "series不能为空") @RequestParam String series) {
        return R.ok(materialInfoService.queryTreeNodeDetail(businessScenarioNo, type, series));
    }

    /**
     * 查询series下金属材料字典列表数据接口
     */
    @SaCheckPermission("isfd:material:query")
    @GetMapping("/list/dictionary/{businessScenarioNo}/{type}")
    @Operation(summary = "通过series，查询金属材料的字典列表数据，例如：\n" +
        "basic.basis,basic.specification,basic.temper,basic.thickness,basic.form\nm",
        security = @SecurityRequirement(name = "system:materialInfo:query"))
    public R<Map<String, Object>> queryBasicBySeries(@NotNull(message = "businessScenarioNo不能为空") @PathVariable String businessScenarioNo,
                                                     @NotNull(message = "type不能为空，目前只能是mat_material") @PathVariable String type,
                                                     @Parameter(description = "series不能为空开") @RequestParam String series) {
        return R.ok(materialInfoService.queryBasicBySeries(businessScenarioNo, type, series));
    }

    /**
     * 按类型统计材料库各类材料的数量接口
     */
    @SaCheckPermission("isfd:material:query")
    @GetMapping("/list/count")
    @Operation(summary = "按类型统计材料库各类材料的数量接口", security = @SecurityRequirement(name = "isfd:material:list"))
    public R<List<MaterialCountObjectVo>> countByMaterialType(@Parameter(description = "businessScenarioNo能为空，多个用逗号隔开", example = "1")
                                                            @RequestParam(required = false) String[] businessScenarioNo,
                                                              @Parameter(description = "type能为空，多个用逗号隔开", example = "mat_material,comp_material")
                                                            @RequestParam(required = false) String[] type) {
        return R.ok(materialInfoService.countByMaterialType(businessScenarioNo, type));
    }

//    /**
//     * 分页查询材料库信息列表
//     */
//    @SaCheckPermission("isfd:material:list")
//    @GetMapping("/list")
//    @Operation(summary = "分页查询材料库信息列表", security = @SecurityRequirement(name = "isfd:material:list"))
//    public TableDataInfo<Map<String, Object>> list(@Parameter(description = "type必传，有comp、mat类型") MaterialInfoBo bo,
//                                                   @Parameter(description = "分页条件，pageNum，pageSize") PageQuery pageQuery) {
//        return materialInfoService.queryPageList(bo, pageQuery);
//    }
//
//    /**
//     * 导出材料库信息列表
//     */
//    @SaCheckPermission("system:materialInfo:export")
//    @Log(title = "材料库信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(@Parameter(description = "type必传，有comp、mat类型") MaterialInfoBo bo,
//                       HttpServletResponse response) {
//        List<Map<String, Object>> list = materialInfoService.queryList(bo);
//        //ExcelUtil.exportExcel(list, "材料库信息", ComacMaterialInfoVo.class, response);
//    }
//
//    /**
//     * 获取材料库信息详细信息
//     *
//     * @param _id 主键
//     */
//    @SaCheckPermission("system:materialInfo:query")
//    @GetMapping("/{_id}")
//    public R<Map<String, Object>> getInfo(
//        @NotNull(message = "type不能为空") @RequestParam String type, @NotNull(message = "主键不能为空") @PathVariable String _id) {
//        return R.ok(materialInfoService.queryById(type, _id));
//    }
//
//    /**
//     * 新增材料库信息
//     */
//    @SaCheckPermission("system:materialInfo:add")
//    @Log(title = "材料库信息", businessType = BusinessType.INSERT)
//    @RepeatSubmit()
//    @PostMapping()
//    public R<Void> add(@Validated(AddGroup.class) @NotNull(message = "type不能为空") @RequestParam String type,
//                       @Parameter(example = "{\n" +
//                           "    \"p_index\": 10002,\n" +
//                           "    \"A11\": 116911.81,\n" +
//                           "    \"A12\": 97508.62,\n" +
//                           "    \"A22\": 188619.44,\n" +
//                           "    \"A66\": 102628.5,\n" +
//                           "    \"D11\": 877035.18,\n" +
//                           "    \"D12\": 205833.37,\n" +
//                           "    \"D22\": 421509.1,\n" +
//                           "    \"D66\": 216770.97,\n" +
//                           "    \"EXX\": 72386.37,\n" +
//                           "    \"EYY\": 32749.08,\n" +
//                           "    \"GXY\": 20269.65,\n" +
//                           "    \"VXY\": 0.52,\n" +
//                           "    \"M_n\": 24\n" +
//                           "}") @RequestBody JSONObject json) {
//        return toAjax(materialInfoService.insertByBo(type, json));
//    }
//
//    /**
//     * 修改材料库信息
//     */
//    @SaCheckPermission("system:materialInfo:edit")
//    @Log(title = "材料库信息", businessType = BusinessType.UPDATE)
//    @RepeatSubmit()
//    @PutMapping()
//    public R<Void> edit(@Validated(EditGroup.class) @NotNull(message = "type不能为空") @RequestParam String type,
//                        @Parameter(example = "{\n" +
//                            "    \"_id\": 666a86f9fd190b4a805e8947,\n" +
//                            "    \"p_index\": 10002,\n" +
//                            "    \"A11\": 116911.81,\n" +
//                            "    \"A12\": 97508.62,\n" +
//                            "    \"A22\": 188619.44,\n" +
//                            "    \"A66\": 102628.5,\n" +
//                            "    \"D11\": 877035.18,\n" +
//                            "    \"D12\": 205833.37,\n" +
//                            "    \"D22\": 421509.1,\n" +
//                            "    \"D66\": 216770.97,\n" +
//                            "    \"EXX\": 72386.37,\n" +
//                            "    \"EYY\": 32749.08,\n" +
//                            "    \"GXY\": 20269.65,\n" +
//                            "    \"VXY\": 0.52,\n" +
//                            "    \"M_n\": 24\n" +
//                            "}") @RequestBody JSONObject bo) {
//        return toAjax(materialInfoService.updateByBo(type, bo));
//    }
//
//    /**
//     * 删除材料库信息
//     *
//     * @param type 材料type
//     * @param _ids 主键串
//     */
//    @SaCheckPermission("system:materialInfo:remove")
//    @Log(title = "材料库信息", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{_ids}")
//    public R<Void> remove(@NotNull(message = "type不能为空") @RequestParam String type,
//                          @NotEmpty(message = "主键不能为空") @PathVariable String[] _ids) {
//        return toAjax(materialInfoService.deleteWithValidByIds(type, List.of(_ids), true));
//    }
}
